home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 6606 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.9 KB  |  58 lines

  1. Newsgroups: comp.lang.c
  2. Path: uu4news.netcom.com!zodiac!szh
  3. From: szh@zcon.com (Syed Zaeem Hosain)
  4. Subject: Re: Watch out!  C "gotcha!"
  5. Message-ID: <1996Feb15.200810.14419@zcon.com>
  6. Sender: szh@zcon.com (Syed Zaeem Hosain)
  7. Nntp-Posting-Host: zodiac
  8. Reply-To: szh@zcon.com
  9. Organization: Z Consulting Group
  10. References: <62ttN_YbnTB@softsite.co.at>
  11. Date: Thu, 15 Feb 1996 20:08:10 GMT
  12.  
  13. In article <62ttN_YbnTB@softsite.co.at>, wsog@softsite.co.at (Walter Sommergruber) writes:
  14. >Michael Schwarz  (mschwarz@winternet.com) wrote on 14.02.96
  15. >about "Watch out!  C "gotcha!"":
  16. >
  17. >>    switch (x)
  18. >>    {
  19. >>       case 1:
  20. >>          printf("It's 1.\n");
  21. >>          break;
  22. >>
  23. >>       defalt:
  24. >>          printf("It's not 1.\n");
  25. >>          break;
  26. >>    }
  27. >[snip]
  28. >> My point is that several compilers we tried this on compiled thismistake
  29. >> with no error or warning.  If you, like so many of us, do not get enough
  30. >> time to completely coverage test your code, this mistake can really bite
  31. >> you on the behind.  Your "default" code will never be executed!
  32. >
  33. >That's no mistake - it's valid C.
  34.  
  35. I think the original poster *realized* that it is valid C code. He was
  36. commenting on the fact that it was an unintentional programming error
  37. that could easily occur. And you would not find out about it till the
  38. operation of the code broke - perhaps in a rare circumstance, when the
  39. default code actually was supposed to be invoked and did not.
  40.  
  41. >"defalt:" is interpreted as a
  42. >label for a potential goto. You write for instance:
  43. >     case 1:
  44. >        printf("abc");
  45. >        if( x ) goto defalt;
  46. >        printf("def");
  47. >     defalt:
  48. >        printf("something else");
  49.  
  50.                                 Z
  51.  
  52.  
  53. -- 
  54. -------------------------------------------------------------------------
  55. | Syed Zaeem Hosain          P. O. Box 610097            (408) 441-7021 |
  56. | Z Consulting Group        San Jose, CA 95161             szh@zcon.com |
  57. -------------------------------------------------------------------------
  58.